package com.kk.permission.utils;

import android.os.Build;
import android.os.Build.VERSION;
import android.text.TextUtils;

import androidx.annotation.RequiresApi;

import java.lang.reflect.InvocationTargetException;

//import com.cootek.smartdialer.pref.Constants;
//import com.meizu.cloud.pushsdk.constants.MeizuConstants;

public class OSUtil {
    public static final String KEY_IS_PHONE_SYSTEM_OPEN_PERMISSION_WILL_BE_KILLED = "key_is_Phone_System_Open_Permission_Will_Be_Killed";
    private static String MIUI_PREFIX = "miui";
    private static final String TAG = "OSUtil";
    public static final String VERSION_NAME_MIUI_V10 = "V10";
    public static final String VERSION_NAME_MIUI_V5 = "V5";
    public static final String VERSION_NAME_MIUI_V6 = "V6";
    public static final String VERSION_NAME_MIUI_V7 = "V7";
    public static final String VERSION_NAME_MIUI_V8 = "V8";
    public static final String VERSION_NAME_MIUI_V9 = "V9";
    public static final int VERSION_TYPE_MIUI_NONE = 0;
    public static final int VERSION_TYPE_MIUI_V5 = 1;
    public static final int VERSION_TYPE_MIUI_V6 = 2;
    private static String sOSName = null;
    private static int sTakeoverToastType = -1;
    private static int sType = -1;

    public static int getProperToastType() {
        if (sType <= 0) {
            synchronized (OSUtil.class) {
                if (sType <= 0) {
                    if ((!isMiui() || isMiuiV5()) && !Build.MANUFACTURER.equalsIgnoreCase("smartisan") && (!Build.MANUFACTURER.equals("OPPO") || VERSION.SDK_INT < 20)) {
                        sType = 2010;
                    } else {
                        sType = 2005;
                    }
                }
            }
        }
        return sType;
    }

    public static int getProperTakeoverToastType() {
        if (sTakeoverToastType <= 0) {
            synchronized (OSUtil.class) {
                if (sTakeoverToastType <= 0) {
                    if ((!isMiui() || isMiuiV5()) && !Build.MANUFACTURER.equalsIgnoreCase("smartisan") && (!Build.MANUFACTURER.equals("OPPO") || VERSION.SDK_INT < 20)) {
                        sTakeoverToastType = 2010;
                    } else {
                        sTakeoverToastType = 2005;
                    }
                }
            }
        }
        return sTakeoverToastType;
    }

    public static boolean isMiui2() {
        boolean z = false;
        try {
            if (Class.forName("miui.os.Build") != null) {
                z = true;
            }
        } catch (ClassNotFoundException unused) {
            return z;
        }
        return false;
    }

    public static boolean isMiui() {
        return isMiui2();
    }

    public static boolean isHuawei() {
        return PackageUtil.isPackageInstalled("com.huawei.systemmanager");
    }

    public static boolean isSamsung() {
        return false;
    }

//    public static boolean isZTE() {
//        return PackageUtil.isPackageInstalled(PackageUtil.ZTE_SETTINGS_PACKAGE_NAMES);
//    }

//    public static String getOSName()
//    {
//        if (sOSName == null) {}
//        for (;;)
//        {
//            Object localObject4;
//            Object localObject1;
//            int i;
//            Object localObject5;
//            int j;
//            try
//            {
//                if (sOSName == null)
//                {
//                    localObject4 = "";
//                    if (isMiui())
//                    {
//                        localObject4 = Build.VERSION.INCREMENTAL;
//                        localObject1 = localObject4;
//                        if (!TextUtils.isEmpty((CharSequence)localObject4))
//                        {
//                            i = 0;
//                            if (i < ((String)localObject4).length())
//                            {
//                                j = ((String)localObject4).charAt(i);
//                                if ((j < 48) || (j > 57)) {
//                                    break;
//                                }
//                                j = 1;
//                                break;
//                            }
//                            localObject1 = ((String)localObject4).substring(i);
//                        }
//                        localObject4 = new StringBuilder();
//                        ((StringBuilder)localObject4).append(MIUI_PREFIX);
//                        ((StringBuilder)localObject4).append("_");
//                        ((StringBuilder)localObject4).append((String)localObject1);
//                        localObject1 = ((StringBuilder)localObject4).toString();
//                    }
//                }
//            }
//            finally {}
//            try
//            {
//                localObject5 = Class.forName("android.os.SystemProperties").getMethod("get", new Class[] { String.class }).invoke(null, new Object[] { "ro.build.version.emui" });
//                localObject1 = localObject5;
//                if (localObject5 != null)
//                {
//                    localObject1 = localObject4;
//                    if ((localObject5 instanceof String)) {
//                        localObject1 = (String)localObject5;
//                    }
//                }
//            }
//            catch (ClassNotFoundException|NoSuchMethodException|IllegalAccessException|InvocationTargetException localClassNotFoundException)
//            {
//                Object localObject3 = localObject4;
//                continue;
//            }
//            sOSName = (String)localObject1;
//            TLog.e(OSUtil.class, "getOSName %s", new Object[] { sOSName });
//            return sOSName;
//            label213:
//            label215:
//            if (j == 0) {
//                i += 1;
//            }
//        }
//        return ;
//    }

    /* JADX WARNING: Removed duplicated region for block: B:9:0x003c A:{Splitter: B:3:0x0012, PHI: r2 , ExcHandler: java.lang.ClassNotFoundException (unused java.lang.ClassNotFoundException)} */
    /* JADX WARNING: Removed duplicated region for block: B:9:0x003c A:{Splitter: B:3:0x0012, PHI: r2 , ExcHandler: java.lang.ClassNotFoundException (unused java.lang.ClassNotFoundException)} */
    /* JADX WARNING: Removed duplicated region for block: B:8:0x003b A:{Splitter: B:1:0x0001, ExcHandler: java.lang.ClassNotFoundException (unused java.lang.ClassNotFoundException)} */
    /* JADX WARNING: Removed duplicated region for block: B:8:0x003b A:{Splitter: B:1:0x0001, ExcHandler: java.lang.ClassNotFoundException (unused java.lang.ClassNotFoundException)} */
    /* JADX WARNING: Missing block: B:8:0x003b, code:
            r2 = false;
     */
    /* JADX WARNING: Missing block: B:9:0x003c, code:
            r1 = TAG;
            r3 = new java.lang.StringBuilder();
            r3.append("isHongMi ");
            r3.append(r2);
            com.cootek.base.tplog.TLog.d(r1, r3.toString(), new java.lang.Object[0]);
     */
    /* JADX WARNING: Missing block: B:10:0x0054, code:
            return r2;
     */
//    public static boolean isHongMi()
//    {
//        Object localObject1;
//        int i;
//        int j;
//        for (;;)
//        {
//            boolean bool2;
//            boolean bool1;
//            try
//            {
//                localObject1 = Class.forName("miui.os.Build");
//                bool2 = ((Class)localObject1).getField("IS_HONGMI").getBoolean(null);
//            }
//            catch (ClassNotFoundException|NoSuchFieldException|IllegalAccessException localClassNotFoundException1)
//            {
//                continue;
//            }
//            try
//            {
//                localObject1 = ((Class)localObject1).getFields();
//                j = localObject1.length;
//                i = 0;
//                bool1 = bool2;
//                if (i < j)
//                {
//                    Object localObject2 = localObject1[i];
//                    StringBuilder localStringBuilder = new StringBuilder();
//                    localStringBuilder.append("fd.name ");
//                    localStringBuilder.append(((Field)localObject2).getName());
//                    TLog.d("OSUtil", localStringBuilder.toString(), new Object[0]);
//                    i += 1;
//                    continue;
//                    bool1 = false;
//                }
//            }
//            catch (ClassNotFoundException|NoSuchFieldException|IllegalAccessException localClassNotFoundException2)
//            {
//                bool1 = bool2;
//            }
//        }
//        localObject1 = new StringBuilder();
//        ((StringBuilder)localObject1).append("isHongMi ");
//        ((StringBuilder)localObject1).append(bool1);
//        TLog.d("OSUtil", ((StringBuilder)localObject1).toString(), new Object[0]);
//        return bool1;
//    }

    public static boolean isMiuiV5() {
        return isMiui() && "V5".equalsIgnoreCase(getMiuiVersionName());
    }

    public static boolean isMiuiV6() {
        return isMiui() && "V6".equalsIgnoreCase(getMiuiVersionName());
    }

    public static boolean isMiuiV7() {
        return isMiui() && "V7".equalsIgnoreCase(getMiuiVersionName());
    }

    public static boolean isMiuiV8() {
        return isMiui() && "V8".equalsIgnoreCase(getMiuiVersionName());
    }

    public static boolean isMiuiV9() {
        return isMiui() && "V9".equalsIgnoreCase(getMiuiVersionName());
    }

    public static boolean isMiuiV10() {
        return isMiui() && VERSION_NAME_MIUI_V10.equalsIgnoreCase(getMiuiVersionName());
    }

    public static int getMiuiVersionType() {
        String miuiVersionName = getMiuiVersionName();
        if ("V5".equalsIgnoreCase(miuiVersionName)) {
            return 1;
        }
        return "V6".equalsIgnoreCase(miuiVersionName) ? 2 : 0;
    }

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public static String getMiuiVersionName2()
    {
        Object localObject = null;
        try
        {
            localObject = Class.forName("android.os.SystemProperties").getMethod("get", new Class[] { String.class }).invoke(null, new Object[] { "ro.miui.ui.version.name" });
            if ((localObject != null) && ((localObject instanceof String))) {
                localObject = (String)localObject;
            }
        }
        catch (ClassNotFoundException|NoSuchMethodException|IllegalAccessException|InvocationTargetException localClassNotFoundException)
        {

        }
        if (localObject == null) {
            return null;
        }
        return ((String)localObject).trim();
    }

    private static String getMiuiVersionName() {
        return "miui";
    }

    public static boolean isAliYunOs()
    {
        try
        {
            Object localObject = Class.forName("android.os.SystemProperties").getMethod("get", new Class[] { String.class }).invoke(null, new Object[] { "ro.yunos.version" });
            if ((localObject != null) && ((localObject instanceof String)))
            {
                boolean bool = TextUtils.isEmpty((String)localObject);
                return bool ^ true;
            }
            return false;
        }
        catch (Exception localException) {}
        return false;
    }

//    public static boolean isSamsung5() {
//        if (PackageUtil.isPackageInstalled(PackageUtil.SAMSUNG_PERMISSION_SETTINGS_PACKAGE_NAMES)) {
//            try {
//                int intValue = Integer.valueOf(VERSION.RELEASE.replace(".", "")).intValue();
//                if ((intValue >= 500 && intValue < 600) || (intValue >= 50 && intValue < 60)) {
//                    return true;
//                }
//            } catch (NumberFormatException unused) {
//                return false;
//            }
//        }
//        return false;
//    }

    public static boolean isSamsung6() {
        String str = VERSION.RELEASE;
        try {
            if (str.contains(".")) {
                str = str.substring(0, str.indexOf("."));
            }
            int intValue = Integer.valueOf(str).intValue();
            if (!isSamsung() || intValue < 6 || intValue >= 7) {
                return false;
            }
            return true;
        } catch (NumberFormatException unused) {
            return false;
        }
    }

    public static boolean isSamsung7() {
        String str = VERSION.RELEASE;
        try {
            if (str.contains(".")) {
                str = str.substring(0, str.indexOf("."));
            }
            int intValue = Integer.valueOf(str).intValue();
            String str2 = TAG;
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(" ");
            stringBuilder.append(intValue);
            if (!isSamsung() || intValue < 7 || intValue >= 8) {
                return false;
            }
            return true;
        } catch (NumberFormatException unused) {
            return false;
        }
    }

    public static boolean isSamsung8() {
        String str = VERSION.RELEASE;
        try {
            if (str.contains(".")) {
                str = str.substring(0, str.indexOf("."));
            }
            int intValue = Integer.valueOf(str).intValue();
            if (intValue < 8 || intValue >= 9) {
                return false;
            }
            return true;
        } catch (NumberFormatException unused) {
            return false;
        }
    }

    public static boolean isSamsungNote3KitKat() {
        return "samsung".equalsIgnoreCase(Build.MANUFACTURER) && "SM-N9009".equals(Build.MODEL) && VERSION.SDK_INT == 19;
    }

    public static boolean isSamsungN9100() {
        return "samsung".equalsIgnoreCase(Build.MANUFACTURER) && "SM-N9100".equals(Build.MODEL) && VERSION.SDK_INT == 23;
    }

    public static boolean isNubioNx569H() {
        return "NX569H".equals(Build.MODEL) && VERSION.SDK_INT == 23;
    }

    public static boolean isJianGuoPro2s() {
        return "OE106".equals(Build.MODEL) && VERSION.SDK_INT == 27;
    }

    public static boolean isVivo() {
//        return PackageUtil.isPackageInstalled("com.iqoo.secure");
        return false;
    }

    public static boolean isVivoSDKManual() {
        return isVivo() && VERSION.SDK_INT < 23;
    }

    public static boolean isVivoAuto() {
        return isVivo() && VERSION.SDK_INT > 23;
    }

    public static boolean isVivoSDK23() {
        return isVivo() && VERSION.SDK_INT == 23;
    }

    public static boolean isVivoX20Android7() {
        return isVivo() && Build.MODEL.contains("X20A") && VERSION.SDK_INT == 25;
    }

    public static boolean isVivoX9iAndroid7() {
        return isVivo() && Build.MODEL.contains("X9i") && VERSION.SDK_INT == 25;
    }

    public static boolean isOppoA57() {
        return Build.MODEL.contains("A57");
    }

    public static boolean isOppoA59() {
        return Build.MODEL.contains("A59");
    }

    public static boolean isOppoX7Aandroid6() {
        return Build.MODEL.contains("X7") && VERSION.SDK_INT == 23;
    }

    public static boolean isOppo1107() {
        return Build.MODEL.contains("1107");
    }

    public static boolean isOppoA33Android5() {
        return Build.MODEL.contains("A33m") && VERSION.SDK_INT == 22;
    }

    public static boolean isOppoA37Android5() {
        return Build.MODEL.contains("A37") && VERSION.SDK_INT == 22;
    }

    public static boolean isOppoR9Tm() {
        return Build.MODEL.contains("R9tm");
    }

    public static boolean isOppoR9m() {
        return Build.MODEL.contains("R9m");
    }

    public static boolean isOppoR9TmAndroid5() {
        return Build.MODEL.contains("R9tm") && VERSION.SDK_INT == 22;
    }

    public static boolean isOppoR11stAndroid7() {
        return Build.MODEL.contains("R11st") && VERSION.SDK_INT == 25;
    }

    public static boolean isXiaoMixAndroid8() {
        return Build.MODEL.contains("MIX") && VERSION.SDK_INT == 26;
    }

    public static boolean isRedmiNote2SDK21() {
        return Build.MODEL.contains("Redmi Note 2");
    }

    public static boolean isMi4cSDKAndroid7() {
        return Build.MODEL.contains("Mi-4c");
    }

    public static boolean isOppoA33m() {
        return Build.MODEL.contains("A33m");
    }

    public static boolean isHuaweiTAGAL00() {
        return Build.MODEL.contains("HUAWEI TAG-AL00") && VERSION.SDK_INT == 22;
    }

    public static boolean isHuaweiBND_AL00_SDK24() {
        return Build.MODEL.contains("BND-AL00") && VERSION.SDK_INT == 24;
    }

    public static boolean isHuaweiNXT_TL00_SDK24() {
        return Build.MODEL.contains("NXT-TL00") && VERSION.SDK_INT == 24;
    }

    public static boolean isHuaweiBLN_TL10_SDK24() {
        return Build.MODEL.contains("BLN-TL10") && VERSION.SDK_INT == 24;
    }

    public static boolean isHuaweiBAC_AL00_SDK24() {
        return Build.MODEL.contains("BAC-AL00") && VERSION.SDK_INT == 24;
    }

    public static boolean isHuaweiKIW_AL10_SDK23() {
        return Build.MODEL.contains("KIW-AL10") && VERSION.SDK_INT == 23;
    }

    public static boolean isHuaweiPLK_AL10_SDK23() {
        return Build.MODEL.contains("PLK-AL10") && VERSION.SDK_INT == 23;
    }

    public static boolean isHuaweiD2_2010() {
        return VERSION.SDK_INT == 19 && Build.MODEL.contains("HUAWEI D2-2010");
    }

    public static boolean isHuaweiChe1_CL20() {
        return VERSION.SDK_INT == 19 && Build.MODEL.contains("Che1-CL20");
    }

    public static boolean isHuaweiAndroid6() {
        return VERSION.SDK_INT == 23 && isHuawei();
    }

    public static boolean isHuaweiAndroid8() {
        return VERSION.SDK_INT == 26 && isHuawei();
    }

    public static boolean isHuaweiAndroid9() {
        return VERSION.SDK_INT == 28 && isHuawei();
    }

    public static boolean isHuaweiMLA_AL00_SDK23() {
        return Build.MODEL.contains("HUAWEI MLA-AL00") && VERSION.SDK_INT == 23;
    }

    public static boolean isHuaweiCAM_AL00_SDK23() {
        return Build.MODEL.contains("CAM-AL00") && VERSION.SDK_INT == 23;
    }

    public static boolean isHuaweiCLT_AL01_SDK28() {
        return Build.MODEL.contains("CLT-AL01") && VERSION.SDK_INT == 28;
    }

    public static boolean isHuaweiSDK23() {
        return VERSION.SDK_INT == 23;
    }

    public static boolean isHuaweiSDK24() {
        return VERSION.SDK_INT == 24;
    }

    public static boolean isHuaweiSDK26() {
        return VERSION.SDK_INT == 26;
    }

    public static boolean isHuaweiSDK27() {
        return VERSION.SDK_INT == 27;
    }

    public static boolean isHuaweiSDK28() {
        return VERSION.SDK_INT == 28;
    }

    public static boolean isHuaweiALP_AL00() {
        return Build.MODEL.contains("ALP-AL00") && VERSION.SDK_INT == 28;
    }

    public static boolean isHuaweiBLA_AL00() {
        return Build.MODEL.contains("BLA-AL00") && VERSION.SDK_INT == 27;
    }

    public static boolean isHuaweiSLA_AL00_SDK24() {
        return Build.MODEL.contains("SLA-AL00") && VERSION.SDK_INT == 24;
    }

    public static boolean isHuaweiP7_L00_SDK22() {
        return Build.MODEL.contains("HUAWEI P7-L00") && VERSION.SDK_INT == 22;
    }

    public static boolean isHuaweiFRD_AL00() {
        return Build.MODEL.contains("FRD-AL00") && VERSION.SDK_INT == 24;
    }

    public static boolean isVivoY85AAndroid8() {
        return Build.MODEL.contains("Y85A") && VERSION.SDK_INT == 27;
    }

    public static boolean isVivoPBAMAndroid8() {
        return Build.MODEL.contains("PBAM") && VERSION.SDK_INT == 27;
    }

    public static boolean isXiaoMi5Android6() {
        return Build.MODEL.contains("MI 5") && VERSION.SDK_INT == 23;
    }

    public static boolean isXiaoMi5sPlusAndroid7() {
        return Build.MODEL.contains("MI 5s Plus") && VERSION.SDK_INT == 24;
    }

    public static boolean isXiaoMi5sPlusAndroid8() {
        return Build.MODEL.contains("MI 5s Plus") && VERSION.SDK_INT == 26;
    }

    public static boolean isXiaoMi8SEAndroid8() {
        return Build.MODEL.contains("MI 8 SE") && VERSION.SDK_INT == 27;
    }

    public static boolean isXiaoMi5S_SDK26() {
        return Build.MODEL.contains("MI 5s") && VERSION.SDK_INT == 26;
    }

    public static boolean isPhoneSystemOpenPermissionWillBeKilled() {
        return isRedMi3sPlusAndroid6() || isRedMiNote4Android6() || isRedMi4Android6() || isRedMiNote5AAndroid7();
    }

    public static boolean isRedMiNote1SAndroid4() {
        return Build.MODEL.contains("HM NOTE 1S") && VERSION.SDK_INT == 19;
    }

    public static boolean isHM1SLTETD() {
        return Build.MODEL.contains("HM 1SLTETD") && VERSION.SDK_INT == 19;
    }

    public static boolean isXiaomiAndroid4() {
        return isMiui() && VERSION.SDK_INT == 19;
    }

    public static boolean isRedMiNote5AAndroid7() {
        return Build.MODEL.contains("Redmi Note 5A") && VERSION.SDK_INT == 25;
    }

    public static boolean isRedMi4Android6() {
        return Build.MODEL.contains("Redmi 4A") && VERSION.SDK_INT == 23;
    }

    public static boolean isRedMiNote4Android6() {
        return Build.MODEL.contains("Redmi Note 4") && VERSION.SDK_INT == 23;
    }

    public static boolean isRedMi3sPlusAndroid6() {
        return Build.MODEL.contains("Redmi 3S") && VERSION.SDK_INT == 23;
    }

    public static boolean isRedMiNote4XAndroid7() {
        return Build.MODEL.contains("Redmi Note 4X") && VERSION.SDK_INT == 24;
    }

    public static boolean isRedMiNote5Android8() {
        return Build.MODEL.contains("Redmi Note 5") && VERSION.SDK_INT == 27;
    }

    public static boolean isRedMi5PlusAndroid7() {
        return Build.MODEL.contains("Redmi 5 Plus") && VERSION.SDK_INT == 25;
    }

//    public static boolean isMeizuM463CAndroid4() {
//        return Build.MODEL.contains("M463C") && PackageUtil.isPackageInstalled("com.meizu.safe") && VERSION.SDK_INT < 21;
//    }

//    public static boolean isMeizuAndroid4() {
//        return PackageUtil.isPackageInstalled("com.meizu.safe") && VERSION.SDK_INT < 21;
//    }

    public static boolean isXiaomiMiui7Android4() {
        return isMiuiV7() && VERSION.SDK_INT == 19;
    }

    public static boolean isXiaomiMiui6Android4() {
        return isMiuiV6() && VERSION.SDK_INT == 19;
    }

    public static boolean isXiaomiMi4cAndroid7() {
        return Build.MODEL.contains("Mi-4c") && VERSION.SDK_INT == 24;
    }

    public static boolean isXiaomiMiui8NoteProAndroid5() {
        return Build.MODEL.contains("MI NOTE Pro") && isMiuiV8() && VERSION.SDK_INT == 22;
    }

    public static boolean isGionee() {
        return Build.MODEL.contains("GN") || Build.MODEL.contains("GIONEE");
    }

    public static boolean isAbove23() {
        return VERSION.SDK_INT >= 23;
    }

    public static boolean isAbove22() {
        return VERSION.SDK_INT >= 22;
    }

    public static boolean isAbove21() {
        return VERSION.SDK_INT >= 21;
    }

    public static boolean isOppoA33SDK22() {
        return Build.MODEL.contains("OPPO A33m") && VERSION.SDK_INT == 22;
    }

    public static boolean sdk23() {
        return VERSION.SDK_INT == 23;
    }

    public static boolean sdk24() {
        return VERSION.SDK_INT == 24;
    }
}
